package net.accenture.palabras.ClienteABMCSpringMVC.cotizador;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceException;




import net.accenture.palabras.ClienteABMCSpringMVC.cliente.Cliente;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional(readOnly = true)
public class CotizacionRepository {
	
	@PersistenceContext
	private EntityManager entityManager;
	
	@Transactional
	public Cotizacion save(Cotizacion cotizacion) {
		entityManager.persist(cotizacion);
		return cotizacion;
	}
	
	public List<Cotizacion> findLikeClienteId(Long idCliente) {
		try {
			
			return entityManager.createNamedQuery(Cotizacion.FIND_LIKE_CLIENTE, Cotizacion.class)
					.setParameter("id", idCliente)
					.getResultList();
		} catch (PersistenceException e) {
			return null;
		}
	}
	
}
